const express = require('express')
const expressStatic = require('express-static')
const cookieParser = require('cookie-parser')
const cookieSession = require('cookie-session')
const bodyParser = require('body-parser')
const multer = require('multer')
const pathLib = require('path')
const consolidate = require('consolidate')

let server = express();
server.listen(8080)
let objMulter = multer({dest: './www/upload/'})
server.use(cookieParser('asdfasdfasdfasdfasdf'));
//post数据
// server.use(bodyParser.urlencoded({extended: false}))
server.use(objMulter.any())

//输出什么东西
server.set('view engine', 'html')
//模板文件放在哪
server.set('views', './views')
//哪种模板引擎
server.engine('html', consolidate.ejs)
server.get('/index',function(req,res,next){
	res.render('1.ejs',{name: 'bule'})
	// if(req.session.userid){
	// 	res.render('1.ejs',{name: 'bule'})
	// }else{
	// 	res.render('login.ejs',{})
	// }
})


//用户请求
// server.post('/',function(req,res,next){
// 	console.log(req.files)
// 	let newName = req.files[0].path + pathLib.parse(req.files[0].originalname).ext
// 	fs.rename(req.files[0].path, newName,function(err){
// 		if(err){
// 			res.send('上传失败')
// 			console.log('上传失败')
// 		}else{
// 			res.send('上传成功')
// 			console.log('上传成功')
// 		}
// 	})
// })
server.use(expressStatic('./www'))